<?php

$user_id = get_loggedin_userid();

$news = dt_list_new_game($user_id);
//var_dump($news);
$dones = dt_list_done_game($user_id);
//var_dump($dones);
if (!$news) {
    $news = array();
}

if (!$dones) {
    $dones = array();
}

$games = array_merge($news, $dones);
//var_dump($games);
if ($games) {
    for($i = 0; $i < count($games); $i++) {
        //var_dump($games[$i]);
        //echo $games[$i]->noun_id;
        //echo $games[$i]->adjective_id;

        $noun_user = dt_get_user_by_user_id($games[$i]->noun_id);
        $adjective_user = dt_get_user_by_user_id($games[$i]->adjective_id);
        //var_dump($noun_user);
        //var_dump($adjective_user);
        if($noun_user) {
            $games[$i]->noun_user_id = $noun_user->user_id;
            $games[$i]->noun_fbid = $noun_user->facebook_id;
            $games[$i]->noun_name = $noun_user->fullname;
        }
        if($adjective_user) {
            $games[$i]->adjective_user_id = $adjective_user->user_id;
            $games[$i]->adjective_fbid = $adjective_user->facebook_id;
            $games[$i]->adjective_name = $adjective_user->fullname;
        }
    }
} else {
    $games = array();
}

echo json_encode(export_result(200, $games));
